package com.macro.mall.portal.service.impl;

import com.macro.mall.mapper.PmsKeywordMapper;
import com.macro.mall.model.PmsKeyword;
import com.macro.mall.model.PmsKeywordExample;
import com.macro.mall.model.UmsMember;
import com.macro.mall.portal.service.PmsKeywordService;
import com.macro.mall.portal.service.UmsMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class PmsKeywordServiceImpl implements PmsKeywordService {

    @Autowired
    private PmsKeywordMapper keywordMapper;
    @Autowired
    private UmsMemberService umsMemberService;


    @Override
    public List<PmsKeyword> getKeyword() {
        UmsMember currentMember = umsMemberService.getCurrentMember();
        PmsKeywordExample example = new PmsKeywordExample();
        PmsKeywordExample.Criteria criteria = example.createCriteria();
        if(currentMember != null && currentMember.getStoreId()!=null){
            criteria.andStoreIdEqualTo(currentMember.getStoreId());
        }else {
            criteria.andStoreIdIsNull();
        }
        List<PmsKeyword> pmsKeywords = keywordMapper.selectByExample(example);
        List<PmsKeyword> result = new ArrayList<>();
        if(!CollectionUtils.isEmpty(pmsKeywords)){
            return pmsKeywords;
        }else{
            return result;
        }
    }
}
